from openpyxl import load_workbook

from xlstoxml import write_to_string_file

languages_map = {'Arabic': 'ar', 'Czech': 'cs', 'Danish': 'da', 'German': 'de', 'Greek': 'el',
                 'Spanish': 'es', 'Finnish': 'fi', 'French': 'fr', 'French Canada': 'fr-rCA', 'Hungarian': 'hu',
                 'Italian': 'it', 'Hebrew': 'iw', 'Japanese': 'ja', 'Korean': 'ko', 'Dutch Netherland': 'nl',
                 'Norwegian': 'nb', 'Polish': 'pl', 'Portugese - Portugal': 'pt', 'Portugese-Brazil': 'pt-rBR',
                 'Romanian': 'ro',
                 'Russian': 'ru', 'Slovak': 'sk', 'Swedish': 'sv', 'Thai': 'th', 'Chinese Simplified - China': 'zh',
                 'Chinese Traditional - Taiwan': 'zh-rTW'}


def main():
    wb = load_workbook('res/PCD_new_translation_output20201207.xlsx')
    ws = wb.get_sheet_by_name('Sheet1')
    key_col = ws['A']
    for col in ws.columns:
        lan = col[0].value
        if lan in languages_map.keys():
            str_dict = {}
            for index, cell in enumerate(col):
                # 忽略第一行
                if index == 0:
                    continue
                str_dict[key_col[index].value] = cell.value
            write_to_string_file('res/origin/values-' + languages_map[lan] + '/strings.xml', str_dict)


if __name__ == '__main__':
    main()
